package com.dl7.mvp.module.manage.albums;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;

import com.dl7.mvp.R;
import com.dl7.mvp.adapter.MyFragmentPagerAdapter;
import com.dl7.mvp.module.base.BaseActivity;
import com.dl7.mvp.module.video.list.AlbumsFragment;
import com.flyco.tablayout.SlidingTabLayout;

import java.util.ArrayList;

import butterknife.BindView;

import static com.dl7.mvp.utils.CommonConstant.ALBUMS_ID;
import static com.dl7.mvp.utils.CommonConstant.ALBUMS_TITLE;

/**
 * 收藏界面
 */
public class AlbumsVideoListActivity extends BaseActivity {

    @BindView(R.id.tool_bar)
    Toolbar mToolBar;
    @BindView(R.id.tab_layout)
    SlidingTabLayout mTabLayout;
    @BindView(R.id.view_pager)
    ViewPager mViewPager;

    MyFragmentPagerAdapter mPagerAdapter;
    private int mId;
    private String mTitle;

    public static void launch(Context context, int id, String title) {
        Intent intent = new Intent(context, AlbumsVideoListActivity.class);
        intent.putExtra(ALBUMS_ID, id);
        intent.putExtra(ALBUMS_TITLE, title);
        context.startActivity(intent);
        ((Activity)context).overridePendingTransition(R.anim.zoom_in_entry, R.anim.hold);
    }

    @Override
    protected int attachLayoutRes() {
        return R.layout.activity_albums_video_list;
    }

    @Override
    protected void initInjector() {
    }

    @Override
    protected void initViews() {
        mId = getIntent().getIntExtra(ALBUMS_ID, 0);
        mTitle = getIntent().getStringExtra(ALBUMS_TITLE);
        mPagerAdapter = new MyFragmentPagerAdapter(getSupportFragmentManager());
    }

    @Override
    protected void updateViews() {
        ArrayList<Fragment> fragments = new ArrayList<>();
        fragments.add(AlbumsFragment.newInstance(mId));
        mTabLayout.setViewPager(mViewPager, new String[]{mTitle}, this, fragments);
        mViewPager.setOffscreenPageLimit(fragments.size());
        mViewPager.setCurrentItem(0);
    }

    @Override
    public void finish() {
        super.finish();
        overridePendingTransition(R.anim.hold, R.anim.zoom_in_exit);
    }
}
